﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Superherochat.Models;
using System.Security.Principal;

namespace Superherochat.Controllers
{
    [Authorize]
    public class ChatController : Controller
    {
        //
        // GET: /Chat/

       

        [HttpGet]
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(string text)
        {
            ChatLog log = ChatLog.Instance;
            MessageInfo m = new MessageInfo();
            m.timestamp = DateTime.Now;
            m.message = text;
            IPrincipal user = HttpContext.User;
            m.userName = user.Identity.Name;
            log.messages.Add(m);

            return View();
        }

        [HttpGet]
        public ActionResult UpdateChatRoom()
        {
            ChatLog log = ChatLog.Instance;
            string s = "";
            foreach (MessageInfo m in log.messages)
            {
                s += m.message + "<br />";
            }
            return Content(s);
        }
    }
}
